﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Core;

namespace EPiSugar.Navigation
{
    public static class EnumerationExtensions
    {
        public static EnumerationAppender Add(this IEnumerable<PageData> pages)
        {
            return new EnumerationAppender(pages);
        }

        public static IEnumerable<PageData> Children(this IEnumerable<PageData> pages)
        {
            foreach (var page in pages)
            {
                foreach(var child in page.Children())
                    yield return child;
            }
        }

        public static IEnumerable<PageData> Parents(this IEnumerable<PageData> pages)
        {
            foreach (var page in pages)
            {
                yield return page.Parent();
            }
        }

        public static IEnumerable<PageData> Descendants(this IEnumerable<PageData> pages)
        {
            return pages.Descendants(int.MaxValue);
        }

        public static IEnumerable<PageData> Descendants(this IEnumerable<PageData> pages, int recursionDepth)
        {
            foreach (var page in pages)
            {
                foreach (var descandant in page.Descendants(recursionDepth))
                    yield return descandant;
            }
        }
    }
}
